package com.cade.agriculturemall.utils;

import android.support.annotation.Nullable;

import com.avos.avoscloud.AVUser;
import com.cade.agriculturemall.model.ServiceAssuranceEntity;
import com.cade.agriculturemall.model.UserInfoEntity;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Lobby on 2017/11/26.
 */

public class ConverUtil {
    //  SA=ServiceAssurance 服务保证
    public static ServiceAssuranceEntity toSAContent(@Nullable int sACode) {
//        List<ServiceAssuranceEntity> sAEntity = null;
        ServiceAssuranceEntity sAEntity = new ServiceAssuranceEntity();
//        for (int i = 0; i < sACode.size(); i++) {

        if (sACode == 1) {
            sAEntity.setTitle("正品保证");
            sAEntity.setContent("该商品由本中国人保承保正品保险");
            return sAEntity;
        } else if (sACode == 2) {
            sAEntity.setTitle("七天无理由退换");
            sAEntity.setContent("消费者在满足七天无理由退换货申请条件的前提下，可以提出“七天无理由退换货”的申请");
            return sAEntity;
        } else if (sACode == 3) {
            sAEntity.setTitle("极速退款");
            sAEntity.setContent("极速退款是为诚信会员提供的退款退货流程的专享特权，额度是根据每个用户当前的信誉评级情况而定");
            return sAEntity;
        } else if (sACode == 4) {
            sAEntity.setTitle("赠运费险");
            sAEntity.setContent("卖家为您购买的商品投保退货运费险");
            return sAEntity;
        } else if (sACode == 5) {
            sAEntity.setTitle("专柜服务");
            sAEntity.setContent("线上购物享受品牌积分与会员权益");
            return sAEntity;
        } else if (sACode == 6) {
            sAEntity.setTitle("闪点到家");
            sAEntity.setContent("提供当日达、次日达、预约配送等物流时效。为履约每个订单赔10元");
            return sAEntity;
        } else if (sACode == 7) {
            sAEntity.setTitle("超值包邮");
            sAEntity.setContent("全场包邮，为您而省");
            return sAEntity;
        } else
            return sAEntity;
    }


    public static String toSexName(@Nullable String sexCode) {
        if (sexCode != null) {
            if (sexCode.equals("1")) {
                return "男";
            } else if (sexCode.equals("2")) {
                return "女";
            } else {
                return "";
            }
        } else {
            return "";
        }
    }

    public static String transOrderStatus(@Nullable String status, int type) {
//        type: 1:showHandle  2:showExpressSpeed
        String code = "";
        String operate = "";
        if (status != null) {
            if (status.equals("0001")) {  //未发货
                code = "1";
                operate = "1";
            } else if (status.equals("0011")) {  //未收货
                code = "2";
                operate = "2";
            } else if (status.equals("0111")) {  //已完成
                code = "3";
                operate = "3";
            } else if (status.equals("1111")) {  //已完成 已评价
                code = "3";
                operate = "4";
            } else if (status.equals("0000")) {      //未支付
                code = "5";
                operate = "5";
            } else if (status.equals("00000")) {      //取消
                code = "6";
                operate = "6";
            }
        }
        if (type == 1) {
            return code;
        } else {
            return operate;
        }
    }

    /**
     * 49    * 获取现在时间
     * 50    *
     * 51    * @return 返回短时间字符串格式yyyy-MM-dd
     * 52
     */
    public static String getStringDateShort() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(currentTime);
        return dateString;
    }

    /**
     * 将长时间格式时间转换为字符串 yyyy-MM-dd HH:mm:ss
     *
     * @param dateDate
     * @return
     */
    public static String dateToStrLong(java.util.Date dateDate) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd ");
        String dateString = formatter.format(dateDate);
        return dateString;
    }

    //    生成唯一订单号，目前规则来看，两个人在同一微秒提交订单重复的概率为1%
    public static String getRandomNo() {
        int r1 = (int) (Math.random() * (10));//产生2个0-9的随机数
        int r2 = (int) (Math.random() * (10));
        long now = System.currentTimeMillis();//一个13位的时间戳
        String paymentID = String.valueOf(r1) + String.valueOf(r2) + String.valueOf(now);// 订单ID
        return paymentID;
    }


    public static String getRandomDealNo() {
        UserInfoEntity user = AVUser.getCurrentUser(UserInfoEntity.class);
        String userId = user.getObjectId();
        String DealNO = "";
        if (userId != null)
            DealNO = getRandomNo() + userId.substring(userId.toString().length() - 4, userId.toString().length());
        return DealNO;
    }


}

